package com.yswy.backstage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yswy.backstage.dto.filter.SysConfigPageFilter;
import com.yswy.backstage.dto.req.GroupsReqVO;
import com.yswy.backstage.dto.req.SysConfigOptionReqVO;
import com.yswy.backstage.dto.res.*;
import com.yswy.backstage.service.ISysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

import static com.yswy.backstage.utils.GldTokenUtils.getUserId;

/**
 * 配置中心 管理
 * @author 19401
 * @date 2022/6/1 11:21
 **/
@RestController
@RequestMapping("/appUser")
@Api(description = "配置中心管理")
public class ConfigCenterController {
    @Autowired
    private ISysConfigService sysConfigService;

    @PostMapping("/sysConfig/page")
    @ApiOperation(value = "参数配置 分页")
    public Page<SysConfigPageResVO> sysConfigPage(@RequestBody @Validated SysConfigPageFilter filter, HttpServletRequest request) {
        return sysConfigService.sysConfigPage(filter, getUserId(request));
    }
    @PostMapping("/sysConfig/create")
    @ApiOperation(value = "参数配置 添加")
    public void sysConfigCreate(@RequestBody @Validated(GroupsReqVO.CREATE.class) SysConfigOptionReqVO req, HttpServletRequest request) {
        sysConfigService.sysConfigCreate(req, getUserId(request));
    }
    @PostMapping("/sysConfig/update")
    @ApiOperation(value = "参数配置 更新")
    public void sysConfigUpdate(@RequestBody @Validated(GroupsReqVO.UPDATE.class) SysConfigOptionReqVO req, HttpServletRequest request) {
        sysConfigService.sysConfigUpdate(req, getUserId(request));
    }
    @GetMapping("/sysConfig/delete")
    @ApiOperation(value = "参数配置 删除")
    public void sysConfigDelete(@RequestParam(value = "id") Long id, HttpServletRequest request) {
        sysConfigService.sysConfigDelete(id, getUserId(request));
    }
}
